import 'package:flutter/material.dart';

/// 自定义的AppBar
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {

  // 标题
  final String title;

  // 显示返回按钮
  final bool showBackButton;

  const CustomAppBar({super.key, required this.title, this.showBackButton = false});

  @override
  Widget build(BuildContext context) {

    // 返回按钮
    void handleBackPress() {
      Navigator.of(context).pop();
    }

    return Container(
      height: 90,
      color: Colors.white,
      padding: const EdgeInsets.only(top: 30),
      child: Stack(
        alignment: Alignment.center,
        children: [
          Text(
            title,
            style: const TextStyle(
              color: Colors.black,
              fontSize: 20,
              fontWeight: FontWeight.bold
            ),
          ),

          if(showBackButton) Positioned(
            left: 16,
            child: GestureDetector(
                onTap: handleBackPress,
                child: const Image(
                    width: 30,
                    height: 20,
                    image: AssetImage("assets/images/icon_back.png")
                )
            ),
          )

        ],
      ),
    );

  }

  @override
  // PreferredSizeWidget的大小
  Size get preferredSize => const Size.fromHeight(90); // 设置AppBar的高度

}